import 'package:flutter/material.dart';
import 'package:wechat_dart/model/converstion.dart'
    show converstions, Converstion;
import '../appConfig.dart' show AppStyles, AppColor, AppFamily, AppWigetSize;

class HomePagesItem extends StatelessWidget {
  // HomePagesItem(
  //     {Key key, @required this.imgUrl, this.time, this.des, this.title})
  //     : assert(imgUrl != null),
  //       super(key: key);
  // final String imgUrl;
  // final String title;
  // final String des;
  // final String time;
  HomePagesItem({Key key, this.converstion})
      : assert(Converstion != null),
        super(key: key);
  final Converstion converstion;
  @override
  Widget build(BuildContext context) {
    Widget unReaderMessage = Container(
      width: AppWigetSize.unReadMessageSize,
      height: AppWigetSize.unReadMessageSize,
      child: Text(
        converstion.unReadMessageCount.toString(),
        style: TextStyle(color: Colors.white, fontSize: 14.0),
        textAlign: TextAlign.center,
      ),
      decoration: BoxDecoration(
        color: Colors.red,
        borderRadius: BorderRadius.all(Radius.elliptical(
            AppWigetSize.unReadMessageSize / 2.0,
            AppWigetSize.unReadMessageSize / 2.0)),
      ),
    );
    List<Widget> childern = [
      Image.asset(
        'assets/images/h_user_ic.png',
        width: AppWigetSize.IconSize,
        height: AppWigetSize.IconSize,
      ),
    ];
    if (converstion.unReadMessageCount > 0.0) {
      childern
        ..add(Positioned(
          child: unReaderMessage,
          right: -6,
          top: -6,
        ));
    }
    Widget Avater = Container(
        padding: EdgeInsets.all(10.0),
        decoration: BoxDecoration(
          borderRadius: BorderRadius.all(Radius.circular(9.0)),
        ),
        child: Stack(overflow: Overflow.visible, children: childern));

    return Row(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        Avater,
        Expanded(
          child: Container(
              padding: EdgeInsets.all(10.0),
              decoration: BoxDecoration(
                  border: Border(
                      bottom: BorderSide(
                          width: 0.5,
                          color: Color(AppColor.ConversionBoderLineColor)))),
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: <Widget>[
                        Text(converstion.title),
                        Text(converstion.des)
                      ],
                    ),
                  ),
                  Column(
                    children: <Widget>[Text(converstion.time)],
                  )
                ],
              )),
        ),
      ],
    );
  }
}

class HomePages extends StatefulWidget {
  @override
  _HomePagesState createState() => _HomePagesState();
}

class _HomePagesState extends State<HomePages> {
  @override
  Widget build(BuildContext context) {
    return ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        return HomePagesItem(
          converstion: converstions[index],
        );
      },
      itemCount: converstions.length,
    );
  }
}
